package org.jeecg.modules.demo.crm.service.impl;

import org.checkerframework.checker.units.qual.A;
import org.jeecg.modules.demo.crm.entity.CBankInfo;
import org.jeecg.modules.demo.crm.entity.CCompanyInfo;
import org.jeecg.modules.demo.crm.entity.CInvoiceInfo;
import org.jeecg.modules.demo.crm.mapper.CCompanyInfoDetailsMapper;
import org.jeecg.modules.demo.crm.mapper.CCompanyInfoMapper;
import org.jeecg.modules.demo.crm.mapper.CInvoiceInfoMapper;
import org.jeecg.modules.demo.crm.service.ICCompanyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Description: 总包主体
 * @Author: jeecg-boot
 * @Date:   2025-06-12
 * @Version: V1.0
 */
@Service
public class CCompanyInfoServiceImpl extends ServiceImpl<CCompanyInfoMapper, CCompanyInfo> implements ICCompanyInfoService {


    @Autowired
    private CCompanyInfoMapper cCompanyInfoMapper;
    @Autowired
    CInvoiceInfoMapper cInvoiceInfoMapper;

    @Autowired
    CCompanyInfoDetailsMapper cCompanyInfoDetailsMapper;

    @Override
    public void add(CCompanyInfo cCompanyInfo) {
        List<CInvoiceInfo> bankInfoList = cInvoiceInfoMapper.findByRelevanceId(cCompanyInfo.getId());
        cCompanyInfo.setId(null);
        cCompanyInfoMapper.insert(cCompanyInfo);
        for (CInvoiceInfo invoice : bankInfoList) {
            invoice.setRelevanceId(cCompanyInfo.getId());
            cInvoiceInfoMapper.updateById(invoice);
        }
    }

    @Override
    public BigDecimal companyAmount(String id) {
        BigDecimal companyAmount = cCompanyInfoDetailsMapper.companyAmount(id);
        return companyAmount;
    }
}
